﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace MultiWallpaperManager
{
	/// <summary>
	/// 스크린 디바이스에 대한 정보와 프리뷰, 스크린에 맞는 이미지 리스트 관리
	/// </summary>
	public class ScreenInformation
	{
		// device
		public string deviceName;
		public bool primary;
		public Rectangle bounds;
		public string displayName;

		public Rectangle previewRect;
		public bool random = true;

		public List<ImageItem> imageItemList = new List<ImageItem>();
		public int selectedImageIndex = -1;

		public Image selectedThumbnail;
		public string selectedImageFilePath;

		// return random image if random flag is set. otherwise, return selected image
		public string GetProperImageFilePath(bool keepCurrentImage)
		{
			if (keepCurrentImage && selectedImageFilePath != null)
				return selectedImageFilePath;

			if (random)
			{
				selectedImageIndex = GetRandomNumber(selectedImageIndex, imageItemList.Count);

				selectedThumbnail = imageItemList[selectedImageIndex].Thumbnail;
				selectedImageFilePath = imageItemList[selectedImageIndex].FilePath;
			}

			return selectedImageFilePath;
		}

		// if generated num is equal to exclude num, retry. max bound is excluded
		private int GetRandomNumber(int excludeNum, int max)
		{
			Random rand = new Random();
			int num = 0;

			do
			{
				num = rand.Next(max);
			}
			while (num == excludeNum);

			return num;
		}

	}
}
